package makeDate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;

public class ADate {

	Date d = new Date();
	GregorianCalendar gc = new GregorianCalendar();
	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
	Date baseDate;
	LinkedList<Integer> timeList;

	String baseTimeStr = "2014-01-07";

	public int initArraylist() {
		timeList = new LinkedList<Integer>();

		timeList.add(1);
		timeList.add(2);
		timeList.add(4);
		timeList.add(7);
		timeList.add(15);
		timeList.add(30);
		timeList.add(60);
		timeList.add(120);
		timeList.add(240);
		timeList.add(480);
		timeList.add(960);

		return 0;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// System.out.print(" xxx ");
		test();

	}

	public ADate() {

		try {
			baseDate = sf.parse(baseTimeStr);
			initArraylist();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getDates(int diff) {

		gc.setTime(d);
		gc.add(Calendar.DATE, -diff);
		// gc.set(gc.get(Calendar.YEAR),gc.get(Calendar.MONTH),gc.get(Calendar.DATE));

		if (baseDate.before(d)) {
			return sf.format(gc.getTime());
		} else {
			return "";
		}

	}

	public static int test() {

		ADate date = new ADate();

		int len = date.timeList.size();
		for (int i = 0; i < len; i++) {
			System.out.println(date.getDates(date.timeList.get(i)));
		}

		return 0;
	}

	public int getTimeList() {

		return 0;

	}

}
